<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>移入移出事件</title>
    <style>
        .red {
            background-color: red;
        }

        .green {
            background-color: green;
        }
    </style>
</head>

<body>
    <div id="one" class="red">内容</div>

    <script>
        var ele = document.getElementById("one");
        ele.onmouseover = function () {
            ele.setAttribute("class", "red");
        }

        ele.onmouseout = function () {
            ele.setAttribute("class", "green");
        }

    </script>
</body>

</html>